// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
import App from './App'
import routes from './router/routers'
import VueScroller from 'vue-scroller'

import  { AlertPlugin,DatetimePlugin,ConfirmPlugin,ToastPlugin } from 'vux'
Vue.use(ToastPlugin)
Vue.use(AlertPlugin)
Vue.use(ConfirmPlugin)
Vue.use(DatetimePlugin)

Vue.use(VueRouter)
Vue.use(VueScroller)
Vue.use(AlertPlugin)

var VueCookie = require('vue-cookie');
Vue.use(VueCookie);

const router = new VueRouter({
  routes
})

// 全局导航钩子
router.beforeEach((to, from, next) => {
  //console.log(getCookie('mobole'))
  if (to.meta.auth) {
    if(getCookie('mobole')) {
      if(to.meta.state){
        //if(getCookie('indstate') == 1){
          if(getCookie('companystate') == 1){
            next();
          }else if(getCookie('companystate') ==0){
            next({path: '/userUnderreview '});
          }else if(getCookie('companystate') == 2){
            next({path: '/userCertificationState'});
          }else if(getCookie('companystate') ==3){
            next({path: '/userUnderreview '});
          }
        //}else {
        //  next({path: '/userCertification'});
        //}
      }else {
        next();
      }

    }else {
      next({
        path: '/entrypass',
        //query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
      })
    }
  }else {
    next();
  }
})
// 增强原方法，好处是旧的业务模块不需要任何变动
VueRouter.prototype.go = function () {
  this.isBack = true
  console.info(this)
  window.history.go(-1)
}

function getCookie(name){
  var arr=document.cookie.split('; ');
  var i=0;
  for(i=0;i<arr.length;i++)
  {
    var arr2=arr[i].split('=');

    if(arr2[0]==name)
    {
      var getC = decodeURIComponent(arr2[1]);
      return getC;
    }
  }

  return '';
}

FastClick.attach(document.body)

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  router,
  render: h => h(App)
}).$mount('#app-box')
